<!DOCTYPE html>
<html>
<head th:include="include/head">

</head>
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">


	<div class="content-wrapper">
		<!-- Content Header (Page header) -->
		<section class="content-header">
			<div class="container-fluid">
				<div class="row mb-2">
					<div class="col-sm-6">
						<h1>内容管理</h1>
					</div>
					<div class="col-sm-6">
						<ol class="breadcrumb float-sm-right">
							<li class="breadcrumb-item"><a href="#">首页</a></li>
							<li class="breadcrumb-item active">内容管理</li>
						</ol>
					</div>
				</div>
			</div>
			<!-- /.container-fluid -->
		</section>
		<section class="content">
			<div class="card card-info">
				<div class="card-header">
					<h3 class="card-title">添加内容</h3>
				</div>
				<!-- /.card-header -->
				<!-- form start -->
				<form class="form-horizontal" id="form" method="post"
					  th:action="@{/content/contentAdd}" enctype="multipart/form-data">
					<div class="card-body">
						<div class="form-group row">
							<label for="titleName" class="col-sm-2 col-form-label">标题名称</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="titleName"
									   id="titleName" placeholder="请输入内容标题 " aria-required="true">
								<label class="help-block m-b-none" for="titleName" id="titleName-error"><i class="far fa-bell"></i>必填项</label>
							</div>
						</div>
						<div class="form-group row">
							<label for="titleShort" class="col-sm-2 col-form-label">短标题名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="titleShort"
									   id="titleShort" placeholder="请输入短标题名 " aria-required="true">
								<label class="help-block m-b-none" for="titleShort" id="titleShort-error"><i class="far fa-bell"></i>必填项</label>

							</div>
						</div>
						<div class="form-group row">
							<label for="titleColor" class="col-sm-2 col-form-label">标题颜色</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="titleColor"
									   id="titleColor" placeholder="标题颜色 " aria-required="true">
							</div>
						</div>
						<div class="form-group row">
							<label for="comId" class="col-sm-2 col-form-label">社区ID</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="comId"
									   id="comId" placeholder="请输入社区ID " aria-required="true">
								<label class="help-block m-b-none" for="comId" id="comId-error"><i class="far fa-bell"></i>必填项</label>

							</div>
						</div>
						<div class="form-group row">
							<label for="actId" class="col-sm-2 col-form-label">活动ID</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="actId"
									   id="actId" placeholder="请输入活动ID " aria-required="true">
								<label class="help-block m-b-none" for="actId" id="actId-error"><i class="far fa-bell"></i>必填项</label>

							</div>
						</div>
						<div class="form-group row">
							<label for="cateId" class="col-sm-2 col-form-label">分类ID</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="cateId"
									   id="cateId" placeholder="请输入分类ID " aria-required="true">
								<label class="help-block m-b-none" for="cateId" id="cateId-error"><i class="far fa-bell"></i>必填项</label>

							</div>
						</div>
						<div class="form-group row">
							<label for="width_Pic" class="col-sm-2 col-form-label">置顶大图</label>
							<div class="col-sm-10">
								<input type="file" class="form-control" name="width_Pic"
									   id="width_Pic"   aria-required="true">
							</div>
						</div>
						<div class="form-group row">
							<label for="height_Pic" class="col-sm-2 col-form-label">高图</label>
							<div class="col-sm-10">
								<input type="file" class="form-control" name="height_Pic"
									   id="height_Pic"   aria-required="true">
							</div>
						</div>

						<div class="form-group row">
							<label for="square_Pic" class="col-sm-2 col-form-label">列表方图</label>
							<div class="col-sm-10">
								<input type="file" class="form-control" name="square_Pic"
									   id="square_Pic"   aria-required="true">
<!--								onchange="uploadImage(this)"-->
							</div>
						</div>
						<div class="form-group row">
							<label for="contentType" class="col-sm-2 col-form-label">文章类型</label>
							<div class="col-sm-10">
								<select id="contentType" name="contentType" class="form-control">
									<option value="">请选择</option>
									<option value="1" >文章</option>
									<option value="2" >链接</option>
								</select>
							</div>
						</div>
						<div class="form-group row">
							<label for="contentUrl" class="col-sm-2 col-form-label">对外地址</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="contentUrl" id="contentUrl"
									   placeholder="对外访问地址" aria-required="true">
							</div>
						</div>

						<div class="form-group row">
							<label for="contentAuthor" class="col-sm-2 col-form-label">作者</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="contentAuthor" id="contentAuthor"
									   placeholder="作者" aria-required="true">
							</div>
						</div>
						<div class="form-group row">
							<label for="contentOrigin" class="col-sm-2 col-form-label">文章来源</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="contentOrigin" id="contentOrigin"
									   placeholder="文章来源" aria-required="true">
							</div>
						</div>
						<div class="form-group row">
							<label for="originUrl" class="col-sm-2 col-form-label">来源地址</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="originUrl" id="originUrl"
									   placeholder="来源地址" aria-required="true">
							</div>
						</div>
						<div class="form-group row">
							<label for="contentDesc" class="col-sm-2 col-form-label">内容描述</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="contentDesc" id="contentDesc"
									   placeholder="内容描述信息" aria-required="true">
							</div>
						</div>
						<div class="form-group row">
							<label for="contentText" class="col-sm-2 col-form-label">内容</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" name="contentText" id="contentText"
									   placeholder="内容" aria-required="true">
							</div>
						</div>

						<div class="card-footer">
							<button type="submit" class="btn btn-info">保存</button>
							<button type="button" class="btn btn-default float-right"
									id="back">取消</button>
						</div>
						<!-- /.card-footer -->
					</div>
				</form>
			</div>
		</section>

	</div>
</div>
<!-- ./wrapper -->
<div th:include="include/foot"></div>
<script>
	// import URLEncoder from "../../static/plugins/jszip/jszip";

	$.validator.setDefaults({
		highlight : function(a) {
			$(a).removeClass("is-valid").addClass(
					"is-invalid");
		},
		success : function(a) {
			$(a).prev().removeClass("is-invalid").addClass(
					"is-valid");
			$(a).html('<i class="fas fa-check"></i>验证成功');
		},
		errorClass:"help-block m-b-none",
// 			validClass:"help-block m-b-none",
		errorPlacement:function(a,b){
			if(b.is(":radio")||b.is(":checkbox")){
				a.appendTo(b.parent().parent().parent())
			}else{
				a.appendTo(b.parent())
			}},
		submitHandler:function(form){loadPage();form.submit();}
	});

	$().ready(function() {
		$("#back").click(function() {
			loadPage();
			location.href = 'userList';
		});
		$("#baseId").change(function (){
			let v=$(this).val();
			let t= $(this).find("option:selected").text();
			console.log(v,t)
			if(v>0){
				$("#baseName").val(t);
				$.ajax({url:'../library/projectList',data:"baseId="+v,success:function (data){
						console.log(data)
						if(data.res){
							$("#projectId").empty();
							$("#projectId").append("<option value=''>请选择</option>");
							for(let i=0;i<data.list.length;i++){
								console.log(data.list[i])
								$("#projectId").append("<option value='"+data.list[i].projectId+"'>"+data.list[i].projectName+"</option>");
							}

						}
					}})
			}else {
				$("#projectId").empty();
				$("#projectId").append("<option value='0'>全部门</option>");
			}

		});
		$("#roleId").change(function() {
			let v=$(this).val();
			let t= $(this).find("option:selected").text();
			let data= $(this).find("option:selected").attr('data');
			console.log(v,t,data)
			if (data=='ROLE_USER'){
				console.log('面试官')
				$('#project').show()
				$('#eName').show()
			}else {
				$('#project').hide()
				$('#eName').hide()
				console.log('其他的')
			}
		});
		$("#form").validate({
			rules : {
				username : {
					required : true,
					checkUsername : true
				},
				password : "required",
				password1 : {
					required : true,
					equalTo : '#password'
				},
				roleId : {
					required : true,
					minlength : 1
				},
				state:{
					required : true,
					minlength : 1
				}

			},
			messages : {
				roleId : '<i class="far fa-times-circle"></i>请选择角色',
				state:'<i class="far fa-times-circle"></i>请选择状态'// 					,
			}
		});
	});
	let loadPage;
	loadPage=function(){
		window.parent.loadPage();
	}
	//图片上传
	function uploadImage(fileDom) {
		//获取文件
		var widthPic = document.getElementById("widthPic").value();
		if (widthPic==""){
			alter("请上传内容")
		}
		//上传图片
		$.ajax({
			url: "/icecCms/content/uploadWidthImage?widthPic="+widthPic,
			type: "post",
			// data: widthPic,
			scriptCharset: 'UTF-8',
			contentType: false,
			processData: false,
			dataType: "json",
			mimeType: "multipart/form-data",
			success: function (data) {
			},
			beforeSend: function () {
			},
			error: function () {
			}
		});
	}
</script>
</body>

</html>